package org.gdstash.ui.select;

import org.gdstash.db.SelectionCriteria;
import org.gdstash.ui.GDStashFrame;
import org.gdstash.ui.util.AdjustablePanel;
import org.gdstash.util.GDMsgFormatter;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.awt.*;

public class DamageDoTPane extends AdjustablePanel {
    private JCheckBox cbPoison;
    private JCheckBox lblAether;
    private JCheckBox lblChaos;
    private JCheckBox cbCold;
    private JCheckBox lblElemental;
    private JCheckBox cbFire;
    private JCheckBox cbLightning;
    private JCheckBox cbPhysical;
    private JCheckBox cbPierce;
    private JCheckBox cbLife;

    public DamageDoTPane() {
        this(1);
    }

    public DamageDoTPane(final int direction) {
        this.adjustUI();
        GroupLayout layout = null;
        GroupLayout.SequentialGroup hGroup = null;
        GroupLayout.SequentialGroup vGroup = null;
        layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        hGroup = layout.createSequentialGroup();
        hGroup.addGroup(layout.createParallelGroup().addComponent(this.cbPoison).addComponent(this.lblAether).addComponent(this.lblChaos).addComponent(this.cbCold).addComponent(this.lblElemental).addComponent(this.cbFire).addComponent(this.cbLightning).addComponent(this.cbPhysical).addComponent(this.cbPierce).addComponent(this.cbLife));
        vGroup = layout.createSequentialGroup();
        vGroup.addGroup(layout.createParallelGroup().addComponent(this.cbPoison)).addGroup(layout.createParallelGroup().addComponent(this.lblAether)).addGroup(layout.createParallelGroup().addComponent(this.lblChaos)).addGroup(layout.createParallelGroup().addComponent(this.cbCold)).addGroup(layout.createParallelGroup().addComponent(this.lblElemental)).addGroup(layout.createParallelGroup().addComponent(this.cbFire)).addGroup(layout.createParallelGroup().addComponent(this.cbLightning)).addGroup(layout.createParallelGroup().addComponent(this.cbPhysical)).addGroup(layout.createParallelGroup().addComponent(this.cbPierce)).addGroup(layout.createParallelGroup().addComponent(this.cbLife));
        if (direction == 0) {
            layout.setHorizontalGroup(vGroup);
            layout.setVerticalGroup(hGroup);
        } else {
            layout.setHorizontalGroup(hGroup);
            layout.setVerticalGroup(vGroup);
        }
        layout.linkSize(0, this.cbPoison, this.lblAether);
        layout.linkSize(0, this.cbPoison, this.lblChaos);
        layout.linkSize(0, this.cbPoison, this.cbCold);
        layout.linkSize(0, this.cbPoison, this.lblElemental);
        layout.linkSize(0, this.cbPoison, this.cbFire);
        layout.linkSize(0, this.cbPoison, this.cbLightning);
        layout.linkSize(0, this.cbPoison, this.cbPhysical);
        layout.linkSize(0, this.cbPoison, this.cbPierce);
        layout.linkSize(0, this.cbPoison, this.cbLife);
        layout.linkSize(1, this.cbPoison, this.lblAether);
        layout.linkSize(1, this.cbPoison, this.lblChaos);
        layout.linkSize(1, this.cbPoison, this.cbCold);
        layout.linkSize(1, this.cbPoison, this.lblElemental);
        layout.linkSize(1, this.cbPoison, this.cbFire);
        layout.linkSize(1, this.cbPoison, this.cbLightning);
        layout.linkSize(1, this.cbPoison, this.cbPhysical);
        layout.linkSize(1, this.cbPoison, this.cbPierce);
        layout.linkSize(1, this.cbPoison, this.cbLife);
    }

    @Override
    public void adjustUI() {
        Font fntLabel = UIManager.getDefaults().getFont("Label.font");
        Font fntCheck = UIManager.getDefaults().getFont("CheckBox.font");
        if (fntCheck == null) {
            fntCheck = fntLabel;
        }
        Font fntBorder = UIManager.getDefaults().getFont("TitledBorder.font");
        if (fntBorder == null) {
            fntBorder = fntLabel;
        }
        fntLabel = fntLabel.deriveFont((float) GDStashFrame.iniConfig.sectUI.fontSize);
        fntCheck = fntCheck.deriveFont((float) GDStashFrame.iniConfig.sectUI.fontSize);
        fntBorder = fntBorder.deriveFont((float) GDStashFrame.iniConfig.sectUI.fontSize);
        final Border lowered = BorderFactory.createEtchedBorder(1);
        final Border raised = BorderFactory.createEtchedBorder(0);
        final Border compound = BorderFactory.createCompoundBorder(raised, lowered);
        final TitledBorder text = BorderFactory.createTitledBorder(compound, GDMsgFormatter.getString(GDMsgFormatter.rbGD, "TXT_DMG_DOT"));
        text.setTitleFont(fntBorder);
        this.setBorder(text);
        if (this.cbPoison == null) {
            this.cbPoison = new JCheckBox();
        }
        this.cbPoison.setText(GDMsgFormatter.getString(GDMsgFormatter.rbGD, "DMGTYPE_ACID_DOT"));
        this.cbPoison.setFont(fntCheck);
        if (this.lblAether == null) {
            this.lblAether = new JCheckBox();
        }
        this.lblAether.setFont(fntCheck);
        this.lblAether.setEnabled(false);
        if (this.lblChaos == null) {
            this.lblChaos = new JCheckBox();
        }
        this.lblChaos.setFont(fntCheck);
        this.lblChaos.setEnabled(false);
        if (this.cbCold == null) {
            this.cbCold = new JCheckBox();
        }
        this.cbCold.setText(GDMsgFormatter.getString(GDMsgFormatter.rbGD, "DMGTYPE_COLD_DOT"));
        this.cbCold.setFont(fntCheck);
        if (this.lblElemental == null) {
            this.lblElemental = new JCheckBox();
        }
        this.lblElemental.setFont(fntCheck);
        this.lblElemental.setEnabled(false);
        if (this.cbFire == null) {
            this.cbFire = new JCheckBox();
        }
        this.cbFire.setText(GDMsgFormatter.getString(GDMsgFormatter.rbGD, "DMGTYPE_FIRE_DOT"));
        this.cbFire.setFont(fntCheck);
        if (this.cbLightning == null) {
            this.cbLightning = new JCheckBox();
        }
        this.cbLightning.setText(GDMsgFormatter.getString(GDMsgFormatter.rbGD, "DMGTYPE_LIGHTNING_DOT"));
        this.cbLightning.setFont(fntCheck);
        if (this.cbPhysical == null) {
            this.cbPhysical = new JCheckBox();
        }
        this.cbPhysical.setText(GDMsgFormatter.getString(GDMsgFormatter.rbGD, "DMGTYPE_PHYSICAL_DOT"));
        this.cbPhysical.setFont(fntCheck);
        if (this.cbPierce == null) {
            this.cbPierce = new JCheckBox();
        }
        this.cbPierce.setText(GDMsgFormatter.getString(GDMsgFormatter.rbGD, "DMGTYPE_PIERCE_DOT"));
        this.cbPierce.setFont(fntCheck);
        if (this.cbLife == null) {
            this.cbLife = new JCheckBox();
        }
        this.cbLife.setText(GDMsgFormatter.getString(GDMsgFormatter.rbGD, "DMGTYPE_VITALITY_DOT"));
        this.cbLife.setFont(fntCheck);
    }

    public void clear() {
        this.cbPoison.setSelected(false);
        this.cbCold.setSelected(false);
        this.cbFire.setSelected(false);
        this.cbLightning.setSelected(false);
        this.cbPhysical.setSelected(false);
        this.cbPierce.setSelected(false);
        this.cbLife.setSelected(false);
    }

    public void addCriteria(final SelectionCriteria criteria) {
        if (this.cbPoison.isSelected()) {
            SelectionCriteria.addStatInfos(criteria, 401);
        }
        if (this.cbCold.isSelected()) {
            SelectionCriteria.addStatInfos(criteria, 404);
        }
        if (this.cbFire.isSelected()) {
            SelectionCriteria.addStatInfos(criteria, 406);
        }
        if (this.cbLightning.isSelected()) {
            SelectionCriteria.addStatInfos(criteria, 408);
        }
        if (this.cbPhysical.isSelected()) {
            SelectionCriteria.addStatInfos(criteria, 409);
        }
        if (this.cbPierce.isSelected()) {
            SelectionCriteria.addStatInfos(criteria, 410);
        }
        if (this.cbLife.isSelected()) {
            SelectionCriteria.addStatInfos(criteria, 407);
        }
    }
}
